// ==========================================================================
// GFast自动生成dao internal操作代码。
// 生成日期：2024-06-11 17:40:12
// 生成路径: internal/app/app/dao/internal/app_user.go
// 生成人：yxfmlbb
// desc:用户表
// company:云南奇讯科技有限公司
// ==========================================================================

package internal

import (
	"context"

	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
)

// AppUserDao is the manager for logic model data accessing and custom defined data operations functions management.
type AppUserDao struct {
	table   string         // Table is the underlying table name of the DAO.
	group   string         // Group is the database configuration group name of current DAO.
	columns AppUserColumns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
}

// AppUserColumns defines and stores column names for table app_user.
type AppUserColumns struct {
	Id        string // ID
	Username  string // 用户名
	Nickname  string // 昵称
	Password  string // 密码
	CreatedAt string // 创建日期
	DeletedAt string // 删除日期
	UpdatedAt string // 更新日期
	Status    string // 状态
	UserType  string // 用户类型
	Age       string // 年龄
	Gender    string // 性别
	Salt      string // 加密盐
	Mobile    string // 联系电话
}

var appUserColumns = AppUserColumns{
	Id:        "id",
	Username:  "username",
	Nickname:  "nickname",
	Password:  "password",
	CreatedAt: "created_at",
	DeletedAt: "deleted_at",
	UpdatedAt: "updated_at",
	Status:    "status",
	UserType:  "user_type",
	Age:       "age",
	Gender:    "gender",
	Salt:      "salt",
	Mobile:    "mobile",
}

// NewAppUserDao creates and returns a new DAO object for table data access.
func NewAppUserDao() *AppUserDao {
	return &AppUserDao{
		group:   "default",
		table:   "app_user",
		columns: appUserColumns,
	}
}

// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *AppUserDao) DB() gdb.DB {
	return g.DB(dao.group)
}

// Table returns the table name of current dao.
func (dao *AppUserDao) Table() string {
	return dao.table
}

// Columns returns all column names of current dao.
func (dao *AppUserDao) Columns() AppUserColumns {
	return dao.columns
}

// Group returns the configuration group name of database of current dao.
func (dao *AppUserDao) Group() string {
	return dao.group
}

// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *AppUserDao) Ctx(ctx context.Context) *gdb.Model {
	return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}

// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *AppUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
